package org.oimwrapper.connectors.common;


import java.util.*;import org.oimwrapper.connectors.*;

/**
 * Prints the current settings for a given IT resource to the log, including encrypted fields.<p>
 *
 * This task expects the following parameters, in addition to the standard
 * parameters in the {@link OIMTaskBase} class.
 * <ul>
 * <li><code>ITResource</code> The name of the IT resource to read the settings from.</li>
 * </ul>
 */
public class OIMITResourceReader extends OIMTaskBase {
    
	/**
	 * True if a stop has been requested for this task.
	 */
	private boolean stop;

	/**
	 * Default constructor.
	 */
	public OIMITResourceReader() {
		super("OIMWRAPPER.TASK");
		stop = false;
	}

	/**
	 * This method is called by the scheduler to execute the task instance.
	 */
	public void execute() {
		try {
			String itResource = getCriticalAttribute("ITResource");
			Map data = getITResData(itResource);
			for (Iterator iterator = data.keySet().iterator(); !stop && iterator.hasNext(); ) {
				 String key = (String) iterator.next();
				 String value = (String) data.get(key);
				 logger.warn(itResource + "[" + key + "] = " + value);
			}
		} catch (Exception e) {
			OIMExceptionHandler.handleException(logger, e, getClass());
		}
	}

	/**
	 * This method is called by the scheduler to stop a running task instance.
	 * 
	 * @return <code>true</code>
	 */
	public boolean stop() {
		logger.warn(" ---- Stopping current task ---- ");
		stop = true;
		return stop;
	}
}